home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / in_sort.zip / INPUT.QB next >
Text File  |  1991-05-01  |  5KB  |  155 lines

  1. REM  This is a series of "GOSUBS" for QuickBasic 2.0 for controlled input.
  2. REM  The routines are:
  3.  
  4. REM       Border: Draws a doubleline border from 3,5 to 23,75. Option of
  5. REM           including title centered on row 3.
  6.  
  7. REM       GeneralInput: Allows input of 1 to Length% characters. Template of ■.
  8. REM            Backspace redraws ■.
  9.  
  10. REM       IntegerInput: As GeneralInput, but allows only numerals. Results
  11. REM            in string.
  12.  
  13. REM       RealInput: As above but allows for input of string representation of
  14. REM            a Real number [Numerals plus . and -]
  15.  
  16. REM       YesNo: Accepts Y,y,N,n. Results in variable YesNo$ and
  17. REM            print "Yes" or "No"
  18.  
  19. REM       AlphaIput: accepts only letters and coverts lower case to Upper Case
  20.  
  21. REM       Note: all routines require an entry [i.e., can not be empty string]
  22.  
  23. REM       Hope my fellow novices can use this!
  24. REM            Paul Friedman CompuServe 75076,127
  25.  
  26. Dot$=chr$(254):Redo$=chr$(29)+dot$+chr$(29)
  27.  
  28. REM **** Example of routines *****
  29.  
  30. Example:
  31.     Title$="Example of Input Routines":gosub Border
  32.  
  33. locate 6,10:Length%=10:Print "Test of General Input: ";:gosub GeneralInput
  34.     general$=Temp$
  35. locate 8,10:Length%=4:Print "Test of IntegerInput: ";:gosub IntegerInput
  36.     Integer$=Temp$
  37. locate 10,10:Length%=7:Print "Test of RealInput: ";:gosub RealInput
  38.     Real$=Temp$
  39. locate 12,10:Length%=8:Print "Test of AlphaInput: ";:gosub AlphaInput
  40.     Alpha$=Temp$
  41. locate 14,10:Print "IS QuickBasic 2.0 buggy?  ";:gosub YesNo
  42.    locate 14,40
  43.     IF YesNo$="Y" THEN
  44.         print "I agree!"
  45.       ELSE print "You must be used to DB3!"
  46.     END IF
  47.  
  48. color 0,7:locate 25,33:Print "Want to rerun?";:color 7,0:print "  ";:gosub YesNo
  49. If YesNo$="Y" then goto Example
  50.  
  51. Title$="Results":gosub Border
  52. locate 6,10:print "General Input: "General$
  53. locate 8,10:print "Integer Input: "Integer$
  54. locate 10,10:print "Real Input:    "Real$
  55. locate 12,10:print "Alpha Input:   "Alpha$
  56. color 0,7: locate 25,33:print "Want to Redo?";:color 7,0:print "  ";:gosub YesNo
  57. If YesNo$="Y" then goto Example
  58.  
  59.  
  60.  
  61. stop
  62. REM   *****  End of Examples
  63.  
  64. REM   *****  Note: For easyof reading, I've given the the Labels and variables     _
  65. REM            long names.
  66.  
  67.  
  68.  
  69. Border:
  70.     CLS
  71.     Locate 3,5:print chr$(201);string$(69,chr$(205));chr$(187);
  72.     For I%=4 to 22
  73.         locate i%,5:print chr$(186);:locate i%,75:print chr$(186);
  74.     Next
  75.     Locate 23,5:print chr$(200);string$(69,chr$(205));chr$(188);
  76.     If Title$="" then
  77.         return
  78.       ELSE locate 3,40-len(title$)\2:print title$
  79.         title$="":return
  80.     END IF
  81. GeneralInput:
  82.     Temp$="":x%=pos(0):y%=csrlin:print string$(Length%,dot$);:locate y%,x%
  83.     GetGen:
  84.         OneChr$=input$(1)
  85.     If OneChr$=chr$(13) and len(Temp$)>0 then
  86.             print space$(Length%-len(Temp$)):return
  87.         ELSEIF OneChr$=chr$(8) and len(Temp$)>0 then
  88.             Temp$=left$(Temp$,len(Temp$)-1):print redo$;:goto GetGen
  89.         ELSEIF len(Temp$)=Length% then
  90.             beep:goto GetGen
  91.         ELSEIF (OneChr$>=" " and OneChr$<="~") then
  92.             Temp$=Temp$+OneChr$:print OneChr$;:goto GetGen
  93.         ELSE beep:goto GetGen
  94.     END IF
  95. IntegerInput:
  96.     Temp$="":x%=pos(0):y%=csrlin:print string$(Length%,dot$);:locate y%,x%
  97.     GetInt:
  98.         OneChr$=input$(1)
  99.     If OneChr$=chr$(13) and len(Temp$)>0 then
  100.             print space$(Length%-len(Temp$)):return
  101.         ELSEIF OneChr$=chr$(8) and len(Temp$)>0 then
  102.             Temp$=left$(Temp$,len(Temp$)-1):print redo$;:goto GetInt
  103.         ELSEIF len(Temp$)=Length% then
  104.             beep:goto GetInt
  105.         ELSEIF (OneChr$>="0" and OneChr$<="9") then
  106.             Temp$=Temp$+OneChr$:print OneChr$;:goto GetInt
  107.         ELSE beep:goto GetInt
  108.     END IF
  109. AlphaInput:
  110.     Temp$="":x%=pos(0):y%=csrlin:print string$(Length%,dot$);:locate y%,x%
  111.     GetAlpha:
  112.         OneChr$=input$(1)
  113.     If OneChr$=chr$(13) and len(Temp$)>0 then
  114.             print space$(Length%-len(Temp$)):return
  115.         ELSEIF OneChr$=chr$(8) and len(Temp$)>0 then
  116.             Temp$=left$(Temp$,len(Temp$)-1):print redo$;:goto GetAlpha
  117.         ELSEIF len(Temp$)=Length% then
  118.             beep:goto GetAlpha
  119.         ELSEIF (OneChr$>="A" and OneChr$<="Z") then
  120.             Temp$=Temp$+OneChr$:print OneChr$;:goto GetAlpha
  121.         ELSEIF (OneChr$>="a" and OneChr$<="z") then
  122.             OneChr$=chr$(asc(OneChr$)-32)
  123.             Temp$=Temp$+OneChr$:print OneChr$;:goto GetAlpha
  124.         ELSE beep:goto GetAlpha
  125.     END IF
  126. RealInput:
  127.     Temp$="":x%=pos(0):y%=csrlin:print string$(Length%,dot$);:locate y%,x%
  128.     GetReal:
  129.         OneChr$=input$(1)
  130.     If OneChr$=chr$(13) and len(Temp$)>0 then
  131.             print space$(Length%-len(Temp$)):return
  132.         ELSEIF OneChr$=chr$(8) and len(Temp$)>0 then
  133.             Temp$=left$(Temp$,len(Temp$)-1):print redo$;:goto GetReal
  134.         ELSEIF len(Temp$)=Length% then
  135.             beep:goto GetReal
  136.         ELSEIF (OneChr$>="0" and OneChr$<="9") then
  137.             Temp$=Temp$+OneChr$:print OneChr$;:goto GetReal
  138.         ELSEIF (OneChr$="." or OneChr$="-") and Temp$="" then
  139.             Temp$=OneChr$:print OneChr$;:goto GetReal
  140.         ELSEIF (OneChr$="." and Temp$<>"" and instr(Temp$,".")=0) then
  141.             Temp$=Temp$+OneChr$:print OneChr$;:goto GetReal
  142.         ELSE beep:goto GetReal
  143.     END IF
  144. YesNo:
  145.     YesNo$="":print redo$;
  146.     GetYesNo:
  147.         YesNo$=input$(1)
  148.     If YesNo$="Y" or YesNo$="y" then
  149.             YesNo$="Y":print "Yes";:return
  150.         ELSEIF YesNo$="N" or YesNo$="n" then
  151.             YesNo$="N":print "No";:return
  152.         ELSE beep:goto GetYesNo
  153.     END IF
  154.  
  155.